/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__server_node_free.c                              */
/*  NOTE      =                                                    */
/*  DATE      = 2015/01/30 by guojq                                */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frhash2.h"
#include "frstat_server.h"
#include "apmtest_cunit.h"

void __server_node_free(Frlist_node* p_node);

extern int g_i_flag_run;
extern unsigned long g_ul_pcap_queue_used;

typedef struct __conn_info {
    unsigned long ul_connections;
    unsigned long ul_requests;
    unsigned long ul_responses;
} conn_info;

typedef struct __conn_avg {
    unsigned long ul_connections[4];
    unsigned long ul_requests[4];
    unsigned long ul_responses[4];
} conn_avg;

typedef struct __server_info {
    u_int   ui_ip;
    u_short us_port;
    int     i_l7_proto;
    
    struct timeval start_time;
    conn_info st_conns_total;
    conn_avg  st_conns_avg;
} Server_info;

//端口关联表
typedef struct __port_related {
    u_int   ui_ip;
    u_short us_port;
    u_int   ui_ip_related;
    u_short us_port_related;
    
    struct timeval start_time;
} Port_related;

//做完关联后的hash节点
typedef struct __server_info_avg {
    u_int   ui_ip;
    u_short us_port;
    int     i_l7_proto;
    
    unsigned long ul_connections;
    unsigned long ul_requests;
    unsigned long ul_responses;
    
    unsigned long ul_connections_avg;
    unsigned long ul_requests_avg;
    unsigned long ul_responses_avg;
} Server_info_avg; 

static int __suite_init(void)
{
	return 0;
}

static int __suite_cleanup(void)
{
	return 0;
}

static void case1(void)
{
    Frlist_node *p_node = NULL;
    __server_node_free(p_node);

    return;

}

static void case2(void)
{
    Frlist_node st_node;
    
    memset(&st_node, 0x00, sizeof(Frlist_node));
    
    st_node.data = NULL;
    __server_node_free(&st_node);

    return;

}

static void case3(void)
{
    Server_info *p_server_info;
    Frlist_node *p_node;

    p_server_info = (Server_info *)frmalloc(sizeof(Server_info));
    
    memset(p_server_info, 0x00, sizeof(Server_info));

    p_node = frlist_node_create(p_server_info);

    __server_node_free(p_node);
    
    frfree(p_node);

    return;

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t__server_node_free 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);
   	CU_add_test(pSuite, "case2", case2);
   	CU_add_test(pSuite, "case3", case3);

    return 0;

}

int main(int argc, char **argv)
{
    fr_slab_init(52428800, "test");
    run_cunit(add_suite);
    fr_slab_destroy();
    return 0;
}